package Test;

import java.util.HashMap;
import java.util.Locale;
import java.util.Scanner;

public class TTT3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < size; i++) {
            HashMap<String, Integer> map = new HashMap<>();
            String line = sc.nextLine();
            String[] lines = line.split(" ");
            int rawLength = Integer.parseInt(lines[0]);
            String block = sc.nextLine();
            String[] blocks = block.split(" ");
            int blockLength = Integer.parseInt(blocks[0]);
            for (int j = 1; j <= rawLength; j++) {
                map.compute(lines[j].toUpperCase(Locale.ROOT), (k, v) -> v == null ? 1 : v + 1);
            }
            for (int j = 1; j <= blockLength; j++) {
//                if (map.containsKey(blocks[j].toUpperCase(Locale.ROOT))){
                    map.remove(blocks[j].toUpperCase(Locale.ROOT));
//                }
            }
            int itemRes = 0;
            for (int j = 1; j <= rawLength; j++) {
                if (map.containsKey(lines[j].toUpperCase(Locale.ROOT)) && map.get(lines[j].toUpperCase(Locale.ROOT)) >itemRes){
                    itemRes = map.get(lines[j].toUpperCase(Locale.ROOT));
                }
            }
            System.out.println(itemRes);
        }
    }
}
